package br.com.tiespec.ejb.Util;

import java.util.Calendar;
import java.util.Date;

public class DataUtils {

	public static final Date getEmptyTime(final Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR, 00);
		cal.set(Calendar.MINUTE, 00);
		cal.set(Calendar.SECOND, 00);
		cal.set(Calendar.MILLISECOND, 00);
		return cal.getTime();
	}

	public static final Date getFullTime(final Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime();
	}

	public static long getDiferencaDias(Date dataInicio, Date dataFim, int parametro) {
		long tempo = ((dataFim.getTime() - dataInicio.getTime()) / 1000);
		switch (parametro) {
			case Calendar.MINUTE:
				return tempo / 60;
			case Calendar.HOUR:
				return tempo / (60 * 60);
			case Calendar.DAY_OF_MONTH:
				return (tempo / (60 * 60)) / 24;
			default:
				return tempo;
		}
	}
}
